$(function () {
    //list content获取数据
    $.get("http://47.104.244.134:8080/goodsbytid.do", { "tid": 13, "page": 1, "limit": 13 }, function (data) {
        console.log(data)
        var data = data.data;
        var str = "";
        for (var i = 0; i < data.length; i++) {
            str += "<li><a href ='details.html?id="+data[i].id+"'> <img src='" + data[i].picurl + "'/></a><p>" + data[i].price + "</p><em>" + data[i].pubdate + "</em><input class='btn' type='button' data-id='"+data[i].id+"' value='加入购物车'></input</li>"
        }
        $(".content ul").html(str);
    });
    
    
})
//添加购物车
var index = 0;
$(".content").on("click","input",function(){
    //拿到对应的商品id
    var goodsId = this.getAttribute("data-id");
    var take = $.cookie("token");
    index++
    $("#span1").html(index)
    console.log(goodsId)
   //添加对应id的购物车
    $.get("http://47.104.244.134:8080/cartsave.do",{ "gid":goodsId, "token":take }, 
    function (data){
     // console.log(data);
  })  
        })
    

